package com.wt.chat.controller;

import com.wt.chat.exception.BaseException;
import com.wt.chat.response.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description
 * @author: wangtao
 * @date:16:08 2019/11/8
 * @email:taow02@jumei.com
 */
@ControllerAdvice
public class ControllerExceptionAdvice {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@ResponseBody
	@ExceptionHandler({BaseException.class}) //指定拦截异常的类型
	public ResponseResult baseExceptionHandler(BaseException e) {
		logger.info("aaaaa");
		return new ResponseResult().code(1).msg(e.getMessage());
	}

	@ResponseBody
	@ExceptionHandler({Exception.class}) //指定拦截异常的类型
	public ResponseResult exceptionHandler(Exception e) {
		logger.info("aaaaa");
		logger.error("safd:",e);
		return new ResponseResult().code(1).msg("系统错误");
	}
}
